import Vue from 'vue'
import './cube-ui'
import App from './App.vue'
import 'amfe-flexible'
import router from './router'
import Axios from 'axios';
import qs from 'qs';
import 'animate.css';
import './theme/fonts/iconfont.css';
import './theme/fonts/iconfont.js';

//my profile
Vue.prototype.$http = Axios;
window.Qs = qs;
//设置储存 sessionStorage
window.iSession = {
  set(key,value){
    if(typeof value == 'object'){
      value = JSON.stringify(value);
    }
    sessionStorage.setItem(key,value);
  },
  get(key){
    var value = sessionStorage.getItem(key);
    try{
      return JSON.parse(value);
    }catch(e){
      return value;
    }
  },
  remove(key){
    sessionStorage.removeItem(key);
  },
  clear(){
    sessionStorage.clear();
  }
}
//设置储存 localStorage
window.iLocal = {
  set(key,value){
    if(typeof value == 'object'){
      value = JSON.stringify(value);
    }
    localStorage.setItem(key,value);
  },
  get(key){
    var value = localStorage.getItem(key);
    try{
      return JSON.parse(value);
    }catch(e){
      return value;
    }
  },
  remove(key){
    localStorage.removeItem(key);
  },
  clear(){
    localStorage.clear();
  }
}
//my profile
Vue.config.productionTip = false;

/**
 * 路由切换
 */
router.beforeEach((to,from,next)=>{
  //页面名称
  switch(to.name){
    case 'index':
      document.title = sysinfo.webname;
      break;
    default:
      document.title = to.meta.title;
      break;
  }
  next();
});

var vm = new Vue({
  router,
  render: h => h(App)
}).$mount('#app')


router.afterEach(()=>{
  setTimeout(()=>{
    window.scroll(0,0);
  },100);
});


